<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
    <link rel="stylesheet"  href="../static/layui/css/layui.css" data-th-href="@{/layui/css/layui.css}">
    <script src="../static/layui/layui.js" data-th-src="@{/layui/layui.js}"></script>

</head>
<body>
<form class="layui-form" >
    <input type="hidden" name="id" data-th-value="${resource?.id}">
    <input type="hidden" name="pid" data-th-if="${resource?.parent}" data-th-value="${resource?.parent?.id}">
    <div class="layui-form-item" data-th-if="${resource?.parent}">
        <label class="layui-form-label">父资源名称：</label>
        <div class="layui-input-inline">
            <input type="text"  readonly data-th-value="${resource?.parent?.name}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">authority：</label>
        <div class="layui-input-inline">
            <input type="checkbox" name="authority"   lay-verify="required" value="c"   data-th-checked="${resource.authority != null}?${#strings.contains(resource?.authority,'c')}"  class="layui-input" title="新增">
            <input type="checkbox" name="authority"   lay-verify="required" value="d"  data-th-checked="${resource.authority != null}?${#strings.contains(resource?.authority,'d')}" class="layui-input" title="删除">
            <input type="checkbox" name="authority"   lay-verify="required" value="u"   data-th-checked="${resource.authority != null}?${#strings.contains(resource?.authority,'u')}"class="layui-input" title="修改">
            <input type="checkbox" name="authority"   lay-verify="required" value="r"   data-th-checked="${resource.authority != null}?${#strings.contains(resource?.authority,'r')}"class="layui-input" title="查询">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">资源类型：</label>
        <div class="layui-input-inline">
            <input type="radio" name="type" value="0" data-th-checked="${resource==null or resource?.type==null or resource?.type==0}"  lay-verify="required"  class="layui-input" title="功能">
            <input type="radio" name="type" value="1" data-th-checked="${resource?.type==1}"  lay-verify="required"  class="layui-input" title="菜单">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">资源名称：</label>
        <div class="layui-input-inline">
            <input type="text" name="name" data-th-value="${resource?.name}"  lay-verify="required" placeholder="请输入资源名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源路径：</label>
        <div class="layui-input-inline">
            <input type="text" name="url" data-th-value="${resource?.url}" placeholder="请输入资源路径" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="sub">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script data-th-inline="javascript">
    //Demo
    layui.use(['form','jquery'], function(){
        let {form,$,layer} = layui;

        //监听提交
        form.on('submit(sub)', function(data){
            $.ajax({
                id:'table_reload',
                url:/*[[@{/resource}]]*/ '/save',
                type:'put',
                data:data.field,
                success:function (rs) {
                    if(rs.code == 0) {
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                        parent.layer.msg(rs.msg,{icon:6});
                        parent.layui.table.reload('table_reload');
                    }else {
                        parent.layer.close(index);
                        parent.layer.msg(rs.msg,{icon:5});
                    }
                }
            })

        });
    });
</script>
</body>
</html>